package com.huawei.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**

 * 创建文件的同时向文件里面写入数据
 */
public class CreateFile2 {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        //conf.set("fs.defaultFS", "hdfs:// master:9000");
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path("/user/test/hdfs/file11.txt");
        FSDataOutputStream dos = fs.create(path);
        System.out.println(path+"文件创建成功");
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(dos));
        bw.write("huawei");
        bw.newLine();
        bw.write("bigdata");
        bw.newLine();
        bw.write("java");
        bw.newLine();
        bw.close();
        dos.close();
        fs.close();
    }
}